import Vue from 'vue'
import VueRouter from 'vue-router'
// import HomeView from '../views/HomeView.vue'
import MovieView from '../views/home/MovieView.vue'


Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/home' },
  {
    path: '/home',
    name: 'home',
    component: MovieView,
    children: [
      { path: '/home', redirect: '/home/reying' },
      { path: '/home/reying', name: 'reying', component: () => import(/* webpackChunkName: "reying" */ '../views/home/ReYing.vue') },
      { path: '/home/daiying', name: 'daiying', component: () => import(/* webpackChunkName: "daiying" */ '../views/home/DaiYing.vue') },
      { path: '/home/yingyuan', name: 'yingyuan', component: () => import(/* webpackChunkName: "yingyuan" */ '../views/home/YingYuan.vue') },
      { path: '/home/jingdian', name: 'jingdian', component: () => import(/* webpackChunkName: "jingdian" */ '../views/home/JingDian.vue') },
    ]

  },
  {
    path: '/video',
    name: 'video',
    component: () => import(/* webpackChunkName: "video" */ '../views/VideoView.vue')
  },
  {
    path: '/small',
    name: 'small',
    component: () => import(/* webpackChunkName: "small" */ '../views/SmallVideo.vue')
  },
  {
    path: '/show',
    name: 'show',
    component: () => import(/* webpackChunkName: "show" */ '../views/ShowView.vue')
  },
  {
    path: '/my',
    name: 'my',
    component: () => import(/* webpackChunkName: "my" */ '../views/MyView.vue')
  },
  {
    path: '/item/:itemid',
    name: 'item',
    component: () => import(/* webpackChunkName: "item" */ '../views/ItemView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "login" */ '../views/LoginView.vue')
  },
  {
    path: '/city',
    name: 'city',
    component: () => import(/* webpackChunkName: "city" */ '../views/CityView.vue')
  },
  {
    path: '*',
    name: '404View',
    component: () => import(/* webpackChunkName: "404View" */ '../views/404View.vue')
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path == '/my') {
    if (localStorage.getItem('user')) {
      next();
    }
    else {
      next('/login');
    }
  }
  else {
    next();
  }
  next();
}
)
export default router
